<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 实现一个简单的案例
        搞两个按钮,一个显示框,这里显示一个整数
        通过点击这两个按钮,一个让整数+1,一个让整数-1
    -->
    <div class="parent">
        <div class="screen">0</div>
        <div class="ctrl">
            <button id="plusButton">+</button>
            <button id="minusButton">-</button>
        </div>
    </div>
    <style>
        *{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        .parent{
            width:500px;
            height:300px;
            background-color: gray;
            margin: 0 auto;
        }
        .parent .screen{
            width: 200px;
            height:150px;
            font-size: 50px;
            margin:0 auto;
            line-height: 150px;
            color: white;

            margin: 0 auto;
            text-align: center;
        }
        .parent .ctrl{
            width:300px;
            height:150px;
            margin: 0 auto;

            display: flex;
             /* 属性用于指定项目在主轴上的对齐方式 */
            justify-content: space-between;   
            align-items: center;
        }
        .parent .ctrl button{
            width: 100px;
            height: 50px;
            font-size: 20px;
            line-height: 20px;
            text-align: center;
            border-radius:10px;
            border: none;
        }
        .parent .ctrl button:active{
            color: white;
            background-color: black;
        }
    </style>
<script>
    //选中这个开关
    let plusButton = document.querySelector('#plusButton');
    //设置点击事件,只要触发这个开关,就会调用这个回调函数
    plusButton.onclick = function(){
        //选中screen元素
        let screen = document.querySelector('.screen');
        //取出screen标签中的元素
        let content = screen.innerHTML;
        //++
        let result = parseInt(content)+1;
        //写回
        screen.innerHTML = result;
        
    }
    let minusButton = document.querySelector('#minusButton');
    minusButton.onclick = function(){
        let screen = document.querySelector('.screen');
        let conten = screen.innerHTML;
        let result = parseInt(conten)-1;
        screen.innerHTML = result;
    } 
</script>
</body>
</html>